package com.zyj.spring.annotationaop.aspect;

import com.zyj.spring.annotationaop.util.BeanUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
@Aspect
public class SetFieldValueAspect {

    @Autowired
    private BeanUtil beanUtil;

    @Around("@annotation(com.zyj.spring.annotationaop.annatation.NeedSetValueField)")
    public Object doSetFieldValue(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        // 执行目标方法，获取结果集
        Object result = proceedingJoinPoint.proceed();
        // 对结果集进行操作
        beanUtil.setBeanFieldValue((Collection) result);
        return result;
    }
}
